package org.example.petitionplatformsystem.controller;

import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import org.example.petitionplatformsystem.service.AiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.codec.ServerSentEvent;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/ai")
public class AiController {
    @Autowired
    private AiService aiService;

    @PostMapping("/send/{userId}")
    public Flux<ServerSentEvent<String>> aiTalk(@PathVariable long userId, @RequestBody String question, HttpServletResponse response) throws NoApiKeyException, InputRequiredException {
        return aiService.aiTalk(userId,question, response);
    }
}
